import * as mine from "../../api/mine";

Page({
    data: {
        tab_list:[{
            label:"日数据",
            value:"DAY"
        },{
            label:"月数据",
            value:"MONTH"
        }],
        
        tabIndex:0,
        currentPage:1,
        createTime:[],
        keyword:"",
        list:[],
        currentPage:1,
        hasNextPage:true,
        total:"",
        orderStatus:"",
        form:{
            currentPage:1,
            pageSize:10,
            shopName:"",
            brandId:"",
            standardCode:"",
            countType:"DAY",
            countDateStart:"",
            countDateEnd:""
        },
        totalApplyGoodNum: "0",
        totalApplyOrderNum: "0",
        totalApplyUserNum: "0"
    },

    onLoad(){

        // this.setData({
        //     hasNextPage:true,
        //     total:"",
        //     currentPage:1,
        //     createTime:[],
        //     tabIndex:0
        // })

        this.get_order_list();
    },
    get_order_list(){

        let form = this.data.form;

        //form.countDate =  form.countDate.length == 0 ? '' : JSON.stringify( form.countDate.join(",") );

        mine.reportData( form )
        .then((res)=>{

            let pageInfo = res.pageInfo;
            let list = pageInfo.list;

            this.setData({
                list:form.currentPage == 1 ? list :[...this.data.list, ...list],
                hasNextPage:pageInfo.hasNextPage,
                total:pageInfo.total,
                totalApplyGoodNum: res.totalApplyGoodNum,
                totalApplyOrderNum: res.totalApplyOrderNum,
                totalApplyUserNum: res.totalApplyUserNum
            })
        })
        .catch(()=>{
            this.setData({
                hasNextPage:false
            })
        })
    },
    top_picker_confirm(e){

        this.setData({
            list:[],
            hasNextPage:true,
            total:"",
            ['form.currentPage']:1,
            ['form.countDateStart']:e.detail[0],
            ['form.countDateEnd']:e.detail[1]
        })

        this.get_order_list();
    },
    handle_tab_change(e){

        this.setData({
            list:[],
            total:"",
            hasNextPage:true,
            ['form.currentPage']:1,
            ['form.countType']:e.detail,
            ['form.countDateStart']:"",
            ['form.countDateEnd']:""
        });

        let topPicker = this.selectComponent('#topPicker');
        topPicker.reset();

        this.get_order_list();
    },
    handle_top_search(e){
        this.setData({
            list:[],
            total:"",
            hasNextPage:true,
            ['form.currentPage']:1,
            ['form.shopName']:e.detail.value
        });

        this.get_order_list();
    },
    top_picker_reset(){

    },
    onReachBottom(){
        if(this.data.hasNextPage){
            this.setData({
                ['form.currentPage']: ++this.data.form.currentPage ,
            })
            this.get_order_list();
        }
    }
})
